package entity;

import java.util.ArrayList;
import java.util.List;

public class Student extends Person {
    private String major;
    private List<Course> selectedCourses = new ArrayList<>();

    public Student(String id, String name, String gender, String major) {
        super(id, name, gender);
        this.major = major;
    }

    public boolean selectCourse(Course course) {
        if (selectedCourses.contains(course)) return false;
        selectedCourses.add(course);
        course.addStudent(this);
        return true;
    }

    public boolean dropCourse(Course course) {
        if (selectedCourses.contains(course)) {
            selectedCourses.remove(course);
            course.removeStudent(this);
            return true;
        }
        return false;
    }

    // 学生课表：包含课程名称、时间、地点、学分、教师
    @Override
    public void printSchedule() {
        System.out.println("\n===== 学生课表 =====");
        System.out.println("学号：" + id);
        System.out.println("姓名：" + name + "（" + gender + "）");
        System.out.println("专业：" + major);
        System.out.println("选课总数：" + selectedCourses.size() + "门");
        System.out.println("---------------------");

        if (selectedCourses.isEmpty()) {
            System.out.println("暂无选课记录");
            return;
        }

        for (Course course : selectedCourses) {
            System.out.println("课程名称：" + course.getName());
            System.out.println("课程ID：" + course.getId());
            System.out.println("上课时间：" + course.getTime());
            System.out.println("上课地点：" + course.getLocation());
            System.out.println("学分：" + course.getCredit());
            System.out.println("授课教师：" + course.getTeacher().getName());
            System.out.println("---------------------");
        }
    }

    public String getMajor() { return major; }
    public List<Course> getSelectedCourses() { return selectedCourses; }
}